<?php
namespace app\monitor\model;

use HtmlParser\ParserDom;

class CategoryInfo
{
	private $htmlDom;

	private $categoryName;
	private $categoryUrl;
	
	public function __construct($url)
	{

			$this->htmlDom = new ParserDom($this->getHtml($url));
			$this->categoryName = $this->htmlDom->find('h3 a',0)->getPlainText();

	}

    private function getHtml($url)
    {
        return $html = file_get_contents($url);
    }

	public function getHtmlDom()
	{
		return $this->htmlDom;
	}

	public function getName()
	{
		return $this->categoryName;
	}

	public function lastUpdateDate($format = TRUE)
	{
		$date = $format ? strtotime($this->htmlDom->find('.date',0)->getPlainText()) : $this->htmlDom->find('.date',0)->getPlainText() ;
		return $date;
	}

	public function updateToNow()
	{
		$days = floor((time()-$this->lastUpdateDate())/86400);
		return $days;
	}
	
}
